
var nn = {
		status_lock:true	
};

nn.connections = {
	cStart:function(){
		this.cEdit();
		
	},
	cEdit:function(){
		if(nn.status_lock){
			var h = dojo.connect(dojo.byId('edytujapp'),'onclick',function(){
				dojo.disconnect(h);
				nn.unlock();
				nn.status_lock = false;
				nn.connections.cEdit();
			});
		}else {
			var h = dojo.connect(dojo.byId('edytujapp'),'onclick',function(){
				dojo.disconnect(h);
				nn.lock();
				nn.status_lock = true;
				nn.connections.cEdit();
			});			
		}

	}	
};
nn.lock = function(){
	dojo.style('em','display','none');
	dojo.style('pm','display','none');
	dojo.query('.lock').forEach(function(node, index, nodelist){
		dojo.style(node,'display','none');
	});
}
nn.unlock = function(){	
	dojo.style('em','display','block');
	dojo.query('.lock').forEach(function(node, index, nodelist){
		dojo.style(node,'display','block');
	});
	console.log('ddd');
	nn.editTab.create();
	
	
};

nn.editTab = {
	tab:undefined,
	data:null,
	create:function(){
		var th = this;
		if(nn.editTab.tab){
			return nn.editTab.tab;			
		}	
		var tc = new dijit.layout.TabContainer({
	        style: "height: 100%; width: 100%;"
		}, "editTab");

		dojo.xhrPost({
            url: "app/edit/edit-tab-data",
            handleAs: "json",
            sync:true,
            load: function(data) {
            	console.log(' -- on Load Data',data);
            	th.data=data;
            },error : function(req){
            	console.log(req);
            }
         });
		/////////////////////////////////////

		
		////////////////////////////////////
		
		
		var cp1 = new dijit.layout.ContentPane({
			title: "Motywy",
			firstvisit:true,
			hand:null,
			onShow: function(){
				nn.editTab.mtData();
				if(this.hand != null){
					dojo.disconnect(this.hand);
				}
				nn.editTab.mtConnect(this);
				
			},
			content: "<div id='idmottab'></div>"
		});
		var cp2 = new dijit.layout.ContentPane({
			title: "Nagłówek",
			firstvisit:true,
			onShow: function(){
		  		var div =dojo.byId('idngtab');
            	div.innerHTML = nn.editTab.data.ng.html;
								
			},
			content: "<div id='idngtab'></div>"
		});		
		var cp3 = new dijit.layout.ContentPane({
		     title: "Ciało strony",
		     firstvisit:true,
		     onShow: function(){
		  		var div =dojo.byId('idbdtab');
            	div.innerHTML = nn.editTab.data.bd.html;
								
		     },
		     content: "<div id='idbdtab'></div>"
		});
		var cp4 = new dijit.layout.ContentPane({
		     title: "Stopka",
		     firstvisit:true,
		     onShow: function(){
				var div =dojo.byId('idfttab');
				div.innerHTML = nn.editTab.data.ft.html;
								
		     },
		     content: "<div id='idfttab'></div>"
		});
		tc.addChild(cp1);
		tc.addChild(cp2);
		tc.addChild(cp3);
		tc.addChild(cp4);
		tc.startup();	
		nn.editTab.tab = tc;
	},
	nd:null,
	mtData:function(){
		dojo.xhrPost({
            url: "app/edit/getmot",
            //handleAs: "json",
            sync:true,
            load: function(data) {
            	//console.log(data);
            	nn.editTab.nd = data;
        		var div =dojo.byId('idmottab');
            	div.innerHTML = data;
            },error : function(req){
            	console.log(req);
            }
         });

	},
	mtConnect:function(obj){
		obj.hand = dojo.connect(dojo.byId('zatwierdz_mot'),'onclick',function(){
			dojo.xhrPost({
	            form: dojo.byId("motform"),
	            url: "app/edit/motyw",
	            handleAs: "json",
	            sync:true,
	            load: function(data) {
	            	
	            	console.log('-- motyw -- connect -- zatwierdz --',data);
	            	dojo.style(dojo.byId('head'),'background-color',data.tlo_naglowka+"");
	            	dojo.style(dojo.byId('body'),'background-color',data.tlo_ciala+"");
	            	dojo.style(dojo.byId('footer'),'background-color',data.tlo_stopki+"");
	            	
	            	dojo.style(dojo.body(),'background-color',data.tlo_strony_kolor+"");
	            	dojo.style(dojo.body(),'color',data.kolor_tresci+"");
	            	dojo.style(dojo.body(),'background-image','url('+data.tlo_strony_url+')');
	            	
	            },error : function(req){
	            	console.log(req);
	            }
	         });
		});
	},
};

nn.render = function(what,how){
	
	
	if(how=='panel'){
		nn.panel.show();
		//dojo.empty('pmcnt');
		
	}
	
	if(what=='baner'){
		nn.panel.renderBanerForm();
	}
	
	
	
	
}





nn.connections.cStart();